﻿
Partial Class goto_page
    Inherits System.Web.UI.Page
    Dim c, connstr, conn, rs, rs1
    Function getText(ByVal tmp, ByVal s, ByVal e)
        'On Error Resume Next
        Dim String1, String2, arrstr, j
        String1 = s
        String2 = e
        Dim fbegin
        Dim fend
        fbegin = 1
        fend = 1
        Do
            fbegin = InStr(fbegin, tmp, String1)
            If fbegin = 0 Then Exit Function
            fend = InStr(fbegin, tmp, String2)
            arrstr = Mid(tmp, fbegin + Len(String1), fend - (fbegin + Len(String1)))
            getText = arrstr
            Exit Do
            fbegin = fend + Len(String2)
        Loop While True
    End Function
    Function getstr(ByVal iRemote)
        On Error Resume Next
        Dim xPost, sGet
        iRemote = iRemote
        xPost = SERVER.CreateObject("msxml2.serverxmlhttp") 'msxml2.serverxmlhttp
        xPost.Open("GET", iRemote, False)
        xPost.setrequestheader("referer", "http://taoke.alimama.com/spreader/search_auction.htm")
        xPost.Send()
        sGet = CreateObject("ADODB.Stream")
        sGet.Mode = 3
        sGet.Type = 1
        sGet.Open()
        sGet.Write(xPost.responseBody)
        sGet.Position = 0
        sGet.Type = 2
        sGet.Charset = "gb2312" ' "gb2312"
        getstr = sGet.ReadText
    End Function
    Function GetPid()
        rs.open("select *  from Config", conn, 1, 3)
        GetPid = rs("Pid").value
        rs.close()
    End Function
    Function GetTaokeUrl()
        Dim cid, code
        cid = Request.QueryString("cid")
        If Left(cid, 6) = "168861" Then
            cid = Right(cid, Len(cid) - 6)
            code = getstr("http://taoke.alimama.com/spreader/gen_auction_code.htm?auction_id=" & cid)
            GetTaokeUrl = getText(code, "txt_urlcode"" name=""foroverflow"">", "</textarea>")
        End If
    End Function
    Function GetShopTaoKeUrl()
        Dim code, shopid
        shopid = request.QueryString("Shopid")
        shopid = mid(shopid, 3, len(shopid) - 4)
        rs.open("select *  from commodity where ShopUserId=" & Int(shopid) & "  and ShopTaokeUrl<>''", conn, 1, 3)
        If Not rs.eof Then
            GetShopTaoKeUrl = rs("ShopTaokeUrl").value
            rs.close()
            Exit Function
        End If
        rs.close()

        rs.open("select *  from commodity where ShopUserId=" & Int(shopid), conn, 1, 3)
        If Not rs.eof Then
            If IsDBNull(rs("ShopTaokeUrl").value) Then
                code = getstr("http://taoke.alimama.com/spreader/adShopList.htm?oriMemberID=" & rs("ShopUserId").value)
                GetShopTaoKeUrl = getText(code, "gen_shop_code.htm?pid=", """ ")
                code = getstr("http://taoke.alimama.com/spreader/gen_shop_code.htm?pid=" & GetShopTaoKeUrl)
                GetShopTaoKeUrl = getText(code, "txt_urlcode"" name=""foroverflow"">", "</textarea>")
                GetShopTaoKeUrl = replace(GetShopTaoKeUrl, "10011550", "Pid")
                If instr(GetShopTaoKeUrl, "=-") Then
                    rs("ShopTaokeUrl").value = GetShopTaoKeUrl
                    rs.update()
                End If
            Else
                If rs("ShopTaokeUrl").value = "" Then
                    code = getstr("http://taoke.alimama.com/spreader/adShopList.htm?oriMemberID=" & rs("ShopUserId").value)
                    GetShopTaoKeUrl = getText(code, "gen_shop_code.htm?pid=", """ ")
                    code = getstr("http://taoke.alimama.com/spreader/gen_shop_code.htm?pid=" & GetShopTaoKeUrl)
                    GetShopTaoKeUrl = getText(code, "txt_urlcode"" name=""foroverflow"">", "</textarea>")
                    GetShopTaoKeUrl = replace(GetShopTaoKeUrl, "10011550", "Pid")
                    If instr(GetShopTaoKeUrl, "=-") Then
                        rs("ShopTaokeUrl").value = GetShopTaoKeUrl
                        rs.update()
                    End If
                Else
                    GetShopTaoKeUrl = rs("ShopTaokeUrl").value
                End If
            End If

        Else
            code = getstr("http://taoke.alimama.com/spreader/adShopList.htm?oriMemberID=" & shopid)
            GetShopTaoKeUrl = getText(code, "gen_shop_code.htm?pid=", """ ")
            code = getstr("http://taoke.alimama.com/spreader/gen_shop_code.htm?pid=" & GetShopTaoKeUrl)
            GetShopTaoKeUrl = getText(code, "txt_urlcode"" name=""foroverflow"">", "</textarea>")
            GetShopTaoKeUrl = Replace(GetShopTaoKeUrl, "10011550", "Pid")
        End If
        rs.close()
    End Function
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        connstr = ConfigurationSettings.AppSettings("SQLConnString") & """" & Server.MapPath(".") & "\" & ConfigurationSettings.AppSettings("dbPath") & """"
        conn = Server.CreateObject("ADODB.Connection")
        conn.open(connstr)
        rs = Server.CreateObject("adodb.recordset")


        'Response.Write(tbCode)
        'Response.End()

    End Sub
End Class
